package insight.google.game.era.data;

import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import com.google.appengine.api.datastore.Key;
import com.google.appengine.api.datastore.KeyFactory;

import javax.jdo.annotations.Inheritance;
import javax.jdo.annotations.InheritanceStrategy;
import javax.jdo.annotations.NotPersistent;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;
import javax.jdo.annotations.Unique;

import org.directwebremoting.annotations.DataTransferObject;
import org.directwebremoting.annotations.RemoteMethod;
import org.directwebremoting.annotations.RemoteProperty;
import org.directwebremoting.proxy.ScriptProxy;

@DataTransferObject
@PersistenceCapable(identityType = IdentityType.APPLICATION,detachable="true")
//@Inheritance(customStrategy = "complete-table")
public class User extends BaseData {

	@Persistent(valueStrategy=IdGeneratorStrategy.IDENTITY)
	@PrimaryKey
	protected Key id;
	
	@RemoteProperty
	@Persistent
	protected String name;
	
	@RemoteProperty
	@Persistent
	protected String roomName ="";
	
	//@RemoteProperty
	@Persistent
	protected Key roomId;
	
	@RemoteProperty
	@Persistent
	protected String email;

	@NotPersistent
	protected ScriptProxy scriptProxy;
	
	@Persistent
	protected Key currentUserHistoryId;
	
	@Persistent
	private boolean isLoggedIn = true;
	
	public User(){
		
	}
	
	
	
	public User(com.google.appengine.api.users.User googUser, String name) {
		if (googUser != null) {
			// this.id = googUser.getUserId();
			if (name == null) {
				this.name = googUser.getNickname();
				if (this.name == null)
					this.name = googUser.getEmail();
			} else {
				this.name = name;
			}
			this.email = googUser.getEmail();
		} else {
			this.name = name;
		}
		
	}
	
	public Key getId() {
		return id;
	}

	public void setId(Key id) {
		this.id = id;
	}

	@RemoteProperty
	public String getName() {
		return name;
	}

	
	public void setName(String name) {
		this.name = name;
	}

	public String getRoomName() {
		return roomName;
	}

	public void setRoomName(String roomName) {
		this.roomName = roomName;
	}

	public Key getRoomId() {
		return roomId;
	}

	public void setRoomId(Key roomId) {
		this.roomId = roomId;
	}
	
//	public void setRoomId(Key roomId) {
//		
//		this.roomId = KeyFactory.keyToString(roomId);
//	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public ScriptProxy getScriptProxy() {
		return scriptProxy;
	}

	public void setScriptProxy(ScriptProxy scriptProxy) {
		this.scriptProxy = scriptProxy;
	}



	public Key getCurrentUserHistoryId() {
		return currentUserHistoryId;
	}



	public boolean isLoggedIn() {
		return isLoggedIn;
	}



	public void setLoggedIn(boolean isLoggedIn) {
		this.isLoggedIn = isLoggedIn;
	}



	public void setCurrentUserHistoryId(Key currentUserHistoryId) {
		this.currentUserHistoryId = currentUserHistoryId;
	}
	
	
	public void reset(){
		this.roomId = null;
		this.roomName = "";
	}
	
	
	
}
